package com.softline.documentsmall.controller;

import com.alibaba.fastjson.JSONArray;
import com.softline.documentsmall.ret.BusinessErrorEnum;
import com.softline.documentsmall.ret.ReturnVO;
import com.softline.documentsmall.ret.ReturnVOUtils;
import com.softline.documentsmall.service.ClassificationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author wph
 * @Date 2021/1/11 16:24
 */
@Api(value = "分类检索相关接口", tags = {"分类检索相关接口"})
@RestController
@RequestMapping("/classification")
@CrossOrigin(allowCredentials = "true", allowedHeaders = "*")
public class ClassificationController {

    @Autowired
    private ClassificationService classificationService;

    /**
     * 根据语种类型查询词条分类列表
     * @param type
     * @return
     */
    @ApiOperation(value = "词条分类列表查询", notes = "词条分类列表查询")
    @GetMapping(value = "/selectList")
    public ReturnVO selectList(@RequestParam(name = "type", defaultValue = "cn") String type) {
        JSONArray resultArray = classificationService.selectList(type);
        if (resultArray!=null&&resultArray.size()!=0) {
            return ReturnVOUtils.success(resultArray);
        } else {
            return ReturnVOUtils.businessFail(BusinessErrorEnum.FAIL);
        }
    }

    /**
     * 根据二级分类名称查询下面的三级分类
     * @param title 二级分类
     * @return
     */
    @ApiOperation(value = "根据二级分类名称查询下面的三级分类", notes = "根据二级分类名称查询下面的三级分类")
    @GetMapping(value = "/selectThirdList")
    public ReturnVO selectThirdList(@RequestParam("title") String title,@RequestParam(name = "type", defaultValue = "cn") String type) {
        JSONArray resultArray = classificationService.selectThirdList(title,type);
        if (resultArray!=null&&resultArray.size()!=0) {
            return ReturnVOUtils.success(resultArray);
        } else {
            return ReturnVOUtils.businessFail(BusinessErrorEnum.FAIL);
        }
    }
}
